package com.study.jobs;

import com.study.constant.RedisConstant;
import com.study.utils.QiniuUtils;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;
import java.util.Set;

public class ClearImgJob {

    @Resource(name = "jedisPool")
    private JedisPool jedisPool;

    public void clearImg(){
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(sdiff != null){
            for (String picName : sdiff) {
                QiniuUtils.deleteFileFromQiniu(picName);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picName);
                System.out.println("清理垃圾图片任务执行:" + picName);
            }
        }


    }
}
